package com.slc.mongodb;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.client.ListCollectionsIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import org.bson.Document;

import java.util.Collection;
import java.util.Set;

/**
 * Created by sunguangzhu on 2015/3/18.
 */
public class MongodbUtil {
    public static void main(String[] args) {

        MongoClient mongoClient = new MongoClient("127.0.0.1");
        MongoDatabase test = mongoClient.getDatabase("sample");
        test.createCollection("m_user");
        MongoCollection<Document> m_user = test.getCollection("m_user");
        m_user.insertOne(new Document());
        long count = m_user.count();
        System.out.println("count = " + count);
        System.out.println("m_user = " + m_user);
//        test.createCollection("aCollection");
//        System.out.println("Collection created successfully");
//        MongoIterable<String> strings = test.listCollectionNames();
//        ListCollectionsIterable<Document> documents = test.listCollections();
//        for (Document document : documents) {
//            Collection<Object> values = document.values();
//        }
//        MongoCollection<Document> aCollection = test.getCollection("bCollection");
//        System.out.println("Collection get successfully");
//        Document document = new Document();
//        document.append("description", "database").
//                append("title", "MongoDB").
//                append("likes", 100).
//                append("url", "http://www.w3cschool.cc/mongodb/").
//                append("by", "w3cschool.cc");
//        aCollection.insertOne(document);
//        System.out.println("Document inserted successfully");

    }
}
